<template>
  <div style="padding: 40px">


    <div style="margin: 10px 0;">
      <el-button type="primary" style="margin-left: 10px;" @click="add">创建反馈</el-button>

    </div>

    <el-table :data="tableData" border stripe style="width: 100%;"  header-align="center" align="center">
      <el-table-column label="反馈ID" width="70px"  header-align="center" align="center">
        <template slot-scope="scope">
          {{ (currentPage - 1) * pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column prop="feedbackType" label="反馈类型"  header-align="center" align="center"/>
      <el-table-column prop="content" label="反馈内容"  header-align="center" align="center" />
      <el-table-column prop="reply" label="反馈答复"  header-align="center" align="center"/>
    </el-table>

    <!-- 新增弹窗 -->
    <el-dialog :visible.sync="dialogVisible" title="创建反馈" width="30%">
      <el-form :model="form" label-width="120px">
        <el-form-item label="反馈类型:">
          <el-input v-model="form.feedbackType" style="width: 50%"></el-input>
        </el-form-item>
        <el-form-item label="反馈内容:">
          <el-input v-model="form.content" style="width: 50%"></el-input>
        </el-form-item>
      </el-form>

      <template #footer>
        <span class="dialog-footer">
          <el-button @click="dialogVisible = false">取消</el-button>
          <el-button type="primary" @click="save">确定</el-button>
        </span>
      </template>
    </el-dialog>


    <!--  分页器-->
    <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-size="pageSize"
        layout="total,prev, pager, next, jumper"
        :total="total">
    </el-pagination>
  </div>

</template>

<script>
import {mapGetters} from 'vuex'
import {

getGuanliyuanQianDao,
  getStudenQianDaoAll
} from '@/http/categories.js'


export default {


  data() {
    return {
      form: {
        "content": "",
        "feedbackType": ""
      },

      dialogVisible: false,
      dialogVisible1: false,
      dialogVisible2: false,
      currentPage: 1,
      pageSize: 10,
      total:0,
      tableData: [],

    }

  },
  created() {
    this.load()
  },


  methods: {


    async load() {
      const {code, message, data} = await  getStudenQianDaoAll({current: this.currentPage, size: this.pageSize})
      console.log(data)
      this.tableData = data.records;
      this.total = Number(data.total)

    },
    add() {
      this.dialogVisible = true
      this.form = {
        "content": "",
        "feedbackType": ""
      }
    },
    // 确认添加
    async save() {
      const {code, message} = await getGuanliyuanQianDao(this.form)
      console.log(this.form)
      if (code == '0') {
        this.$message({
          type: "success",
          message: "添加成功"
        })
      } else {
        this.$message({
          type: "error",
          message: "添加失败"
        })
      }
      this.dialogVisible = false
      this.load()
    },

    handleSizeChange(pageSize ) {
      this.pageSize = pageSize;
      this.currentPage = 1;
      this.load()
    },
    async handleCurrentChange(pageNum) {
      this.currentPage = pageNum
      const { code, message, data } = await getStudenQianDaoAll({ current: pageNum, size: this.pageSize })
      console.log(data)
      this.tableData = data.records
      this.total= Number(data.total)
      this.load(); // 重新加载数据
    },
    onDaloag(row) {
      this.form1 = row
      this.dialogVisible2 = true
    }

  },
  computed: {
    ...mapGetters({
      userRole: 'user/getUserRole'
    })
  }

}
</script>

<style></style>
